<template>
	<view class="goods_list">
		<scroll-view class="top_category" scroll-x="true">
			<!-- <view @click="leftClickHandle(index,item.id)" :class="active===index?'active':''" v-for="(item,index) in cates" :key="item.id">
				{{item.title}}
			</view> -->
			<view class="active">辣条类</view>
			<view>饼干类</view>
			<view>面包类</view>
			<view>饮料类</view>
			<view>饮料类1</view>
			<view>饮料类2</view>
			<view>饮料类3</view>
		</scroll-view>
		<goods-list @goodsItemClick="toGoodsDetail" :goods="goods"></goods-list>
	</view>
</template>

<script>
	import goodsList from "../../components/goods-list.vue"
	export default {
		data() {
			return {
				goods: [],
				page: 1,
				total: 0,
				flag: false,
				category: []
			}
		},
		components: {
			"goods-list": goodsList
		},
		onLoad() {
			this.getGoodsList()
		},
		methods: {
			getGoodsList(callBack) {
				// uni.request({
				// 	url: "/xxx?page=" + this.page,
				// 	success: (res) => {
				// 		console.log(res.data)
				// 		if (res.data.data.code == 0) {
				// 			return uni.showToast({
				// 				title: "获取数据失败"
				// 			})
				// 		}
				// 		this.goods = [...this.goods, ...res.data.data]
				// 		// this.total = res.data.data.total)
				// 		this.slideshows = res.data.data.slides
				// 		callBack && callBack()
				// 	}
				// })
				this.goods = [{
						id:1,
						img_url:"http://localhost:8080/static/imgs/cat.jpg",
						price:"19",
						name:"伸腿瞪眼丸"
					},
					{
						id:2,
						img_url:"http://localhost:8080/static/imgs/dog.jpg",
						price:"109",
						name:"鹤顶红"
					},
					{
						id:3,
						img_url:"http://localhost:8080/static/imgs/1.jpg",
						price:"19.9",
						name:"伸腿瞪眼丸"
					},]
			},
			toGoodsDetail(id){
				uni.navigateTo({
					url:"/pages/goods-detail/goods-detail?id="+id
				})
			}
		},
		onReachBottom() {
			//触底翻页
			if (this.goods.length < this.total) return this.flag = true
			this.page++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			//下拉刷新
			this.page = 1
			this.goods = []
			this.flag = false
			setTimeout(() => {
				this.getGoodsList(() => {
					uni.stopPullDownRefresh()
				})
			}, 1000)
		}
	}
</script>

<style lang="scss">
	.goods_list {
		background: #eee;

		.top_category {

			width: 100%;
			height: 70rpx;
			background: white;
			white-space: nowrap;

			view {
				width: 13%;
				line-height: 70rpx;
				font-size: 15px;
				text-align: center;
				padding: 0 12rpx;
				// border-right: 1rpx solid #eee;
				display: inline-block;
			}

			.active {
				border-bottom: 4rpx solid #FF6A6A;
				color: #FF6A6A;
			}
		}
	}
</style>
